package com.kingyun.gpsinspection.purificationservice.services.tdm.outerservice.impl;

import com.alibaba.fastjson.JSONObject;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.tdm.TdmWorkOrderMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.tdm.WorkOrder;
import com.kingyun.gpsinspection.purificationservice.facade.model.tdm.WorkOrderVo;
import com.kingyun.gpsinspection.purificationservice.facade.service.tdm.WorkOrderWebService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by sugongche on 2017/2/15.
 */
public class WorkOrderWebServiceImpl implements WorkOrderWebService {
    @Autowired
    private TdmWorkOrderMapper tdmWorkOrderMapper;

    @Override
    public WorkOrderVo queryVoById(String workOrderId) {
        if (StringUtils.isBlank(workOrderId)) {
            return null;
        }

        WorkOrderVo workOrderVo = tdmWorkOrderMapper.queryByPrimaryKey(workOrderId);

        return workOrderVo;
    }

    /**
     * 查询工单
     *
     * @param workOrderVo 查询条件封装类
     * @return JSONObject
     */
    @Override
    public JSONObject queryWorkOrderList(WorkOrderVo workOrderVo) {
        JSONObject jsonObject = new JSONObject();
        workOrderVo.setLimit(workOrderVo.getLimit() == null ? 10 : workOrderVo.getLimit());
        workOrderVo.setOffset(workOrderVo.getOffset() == null ? 0 : workOrderVo.getOffset());
        jsonObject.put("total", tdmWorkOrderMapper.queryCount(workOrderVo));
        List<WorkOrder> list = tdmWorkOrderMapper.queryList(workOrderVo);
        jsonObject.put("rows", list);
        return jsonObject;
    }

    /**
     * 查询工单详细
     *
     * @param workOrderId 工单id
     * @return JSONObject
     */
    @Override
    public WorkOrderVo queryWorkOrderDetail(String workOrderId) {
        WorkOrderVo workOrderVo = tdmWorkOrderMapper.queryByPrimaryKey(workOrderId);
        return workOrderVo;
    }
}
